// 获取树形结构的数据
export const getTree = (arr) => {
  const tmp = {};
  const res = [];

  arr.forEach((item) => {
    tmp[item.id] = item;
  });

  arr.forEach((item) => {
    const current = tmp[item.id];
    if (+item.pid === 0 || !tmp[item.pid]) {
      res.push(current);
    } else {
      tmp[item.pid].children = tmp[item.pid].children || [];
      tmp[item.pid].children.push(current);
    }
  });
  return res;
};
